/* Copyright (C) 2010 Fredrique Samuels, fredriquesamuels@gmail.com */

/*
  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#ifndef TRI_SCENE_H_
#define TRI_SCENE_H_

#include <GL/gl.h>
#include <GL/glu.h>

#include "camera.h"
#include "entity.h"

namespace tri{
class TSceneCache;

class TScene:public TAbstractEntityParent,public TAbstractEventComponent{
	
	friend class TSceneCache;
	
protected:
	typedef std::set<TEntity*> TEntitySet;
	typedef std::set<TEntity*>::const_iterator ConstIterator;
public:
	TScene();
	TScene(std::string n);
	virtual ~TScene();
	
	void setName(std::string);
	std::string getName() const;
	
	void render();
	virtual void show();
	virtual void hide();
	virtual void onResize(int w, int h);
	TSceneCache* getParent();
	virtual void update();
	TCamera* getCamera();
	
	//inherited from TAbtractEntityParent
	virtual void removeAll();
	void removeEntity(TEntity*);
	void addEntity(TEntity*);
	bool hasEntity(TEntity* child);
	void getEntitySet(std::set<TEntity*>& EntSet);
	TEntity* getEntity(unsigned int uid);
	
private:
	std::string m_Name;
	TSceneCache* m_Parent;
	std::set<TEntity*> m_EntitySet;
	TCamera m_Camera;
};

class TSceneCache{
public:
	TSceneCache();
	virtual ~TSceneCache();
	
	void update();
	void render();
	int addScene(std::string key,TScene* scene);
	TScene* getScene(std::string key);
	void removeScene(std::string key);
	void removeAll();
	bool setActiveScene(std::string key);
	TScene* getActiveScene();
	void getSceneList(std::vector<std::string>& list);
	bool contains(std::string);
	void setCamera();
private:
	
	std::string m_CurrentScene;
	std::string m_LastActiveScene;
	std::map<std::string, TScene*> m_SceneMap;
	
};

}
#endif /*DISPLAY_ENGINE_H_*/
